from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime, Float, Text
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class DownloadProgressRecord(Base):
    __tablename__ = 'download_progress'
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'mysql_charset': 'utf8mb4',
        'mysql_collate': 'utf8mb4_unicode_ci'
    }
    
    task_id = Column(String(36), primary_key=True)
    description = Column(String(500))
    total_size = Column(Integer, nullable=False)
    downloaded_size = Column(Integer, default=0)
    speed = Column(Float, default=0)  # bytes/s
    status = Column(String(20), nullable=False)  # pending, downloading, completed, failed
    error = Column(Text)
    started_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) 